home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10946 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: cs.tu-berlin.de!news
  2. From: Roman Lechtchinsky <wolfro@cs.tu-berlin.de>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Inheritance and function signatures
  5. Date: Mon, 11 Mar 1996 19:47:30 +0100
  6. Organization: Technical University of Berlin
  7. Message-ID: <31447542.6E69@cs.tu-berlin.de>
  8. References: <MANOWAR.96Mar11132010@dilo.engin.umich.edu>
  9. NNTP-Posting-Host: 130.149.17.231
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (Win95; I)
  14.  
  15. Krisztian Flautner wrote:
  16. > Take the following example:
  17. >     #include <iostream.h>
  18. >     class A {
  19. >     public:
  20. >         virtual void print();
  21. >         virtual void print(int a, int b) = 0;
  22. >     };
  23. >     class B : public A {
  24. >     public:
  25. >         void print(int a, int b);
  26. >     };
  27. >     void A::print()
  28. >     {
  29. >         cout << "A::print()" << endl;
  30. >     }
  31. >     void B::print(int a, int b)
  32. >     {
  33. >         cout << "B::print(int " << a << ", int " << b << ")" << endl;
  34. >     }
  35. >     main()
  36. >     {
  37. >         B* bb;
  38. >         bb = new B();
  39. >         bb->print();
  40. >     }
  41. > I was surprised to see that the call to bb->print() causes an error using
  42. > several compilers. G++ produces the following error message:
  43. >     t.cc: In function `int main()':
  44. >     t.cc:34: too few arguments for method `void B::print(int, int)'
  45. > It seems that function signitures are not properly inherited. Is this
  46. > a bug or a feature ?
  47.  
  48. A function defined in a derived class hides all inherited functions with the 
  49. same name. It is defined this way in the April draft as well as in the 
  50. original language. Use a qualifier to correct this problem: bb->A::print() ( 
  51. and thank God it's not a virtual function ). A rather annoying rule, isn't 
  52. it?
  53.  
  54. Bye
  55.  
  56. Roman
  57.